﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "网上成绩录入");
		
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		targetArgs = structNew();
		
		turnId = event.getArg("MT");
		termId = event.getArg("TID", event.getArg("TermID"));
		currentTab = event.getArg("TabID", "labSetting");
		
		rs_turnEntity = queryNew("mt");
		
		sql = "	SELECT
					mt.mt,mt.date_start,mt.date_end,mt.time_start,mt.time_end,mt.institute_allowed,mt.lease_date
				FROM
					t_mark_turn mt
				ORDER BY
					mt.mt";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_turn = queryObj.execute(sql = sql).getResult();
		
		if ( len(turnId) ) {
			
			sql = "	SELECT
						mt.mt,mt.date_start,mt.date_end,mt.time_start,mt.time_end,mt.institute_allowed,mt.lease_date
					FROM
						t_mark_turn mt
					WHERE
						mt.mt= :turnId ";
						
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "turnId", value = turnId, cfsqltype = "cf_sql_char");
			rs_turnEntity = queryObj.execute(sql = sql).getResult();
			
			if( rs_turnEntity.recordCount ) {
				currentTab = "labEdit";
			}
		
		}
			
		/* 读取开课学院信息 */
		
		sql = "	SELECT
					a.institute_id,a.institute_short
				FROM
					t_institute a
				WHERE
					EXISTS(
						SELECT 1 FROM t_task b
							INNER JOIN t_course bc ON bc.cid = b.cid
							INNER JOIN t_institute bci ON bci.institute_id = bc.institute_id
						WHERE
							bci.institute_id = a.institute_id
							AND
							b.term_id = :termId 
							AND
							SUBSTR(b.task_prop,7,1) = '0'
					)
					OR
					EXISTS(
						SELECT 1 FROM t_common_task b
						INNER JOIN t_course bc ON bc.cid = b.cid
						WHERE
							bc.institute_id = a.institute_id
						AND
							b.term_id = :termId 
						AND
							SUBSTR(b.task_prop,7,1) = '0'
					
					)
				ORDER BY
					a.institute_short";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_ins = queryObj.execute(sql = sql).getResult();
		
		/* 学院成绩提交情况 */
		/* olapArray [ DepID, DepName, 进行中, 已完成, 未录入 ] */
		
		olapArray = [];
		
		/* 未录入 */
		
		sql = "	SELECT
					ac.institute_id,COUNT(*) r_count
				FROM
					t_task a INNER JOIN t_course ac ON ac.cid = a.cid
				WHERE
					a.term_id = :termId 
					AND
					NOT EXISTS(SELECT 1 FROM t_task_mark b WHERE a.tsk_id = b.task_id AND b.term_id = :termId )
					AND
					SUBSTR(a.task_prop,7,1) = '0'
				GROUP BY
					ac.institute_id";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_planTask = queryObj.execute(sql = sql).getResult();
		
		sql = "	SELECT
					ac.institute_id,COUNT(*) r_count
				FROM
					t_common_task a INNER JOIN t_course ac ON ac.cid = a.cid
				WHERE
					a.term_id = :termId 
					AND
					NOT EXISTS(SELECT 1 FROM t_task_mark b WHERE a.tsk_id = b.task_id AND b.term_id = :termId )
					AND
					SUBSTR(a.task_prop,7,1) = '0'
				GROUP BY
					ac.institute_id";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_commonTask = queryObj.execute(sql = sql).getResult();
		
				
		/* 已进入成绩录任务 */
		
		sql = "	SELECT
					 c.institute_id,tm.task_prog,COUNT(*) r_count
				FROM
					t_task_mark tm INNER JOIN t_course c ON tm.cid = c.cid
				WHERE
					tm.term_id = :termId 
				GROUP BY
					c.institute_id,tm.task_prog";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_taskMark = queryObj.execute(sql = sql).getResult();
		

		for(a = 1; a le rs_ins.recordCount; a++){
			
			/* 重构结果数据 */
			olap = [ rs_ins['institute_id'][a], rs_ins['institute_short'][a], 0, 0, 0 ];

			for(b = 1;b le rs_planTask.recordCount; b++){
				if ( rs_ins['institute_id'][a] eq rs_planTask['institute_id'][b] ) {
					olap[5] = olap[5] + rs_planTask['r_count'][b];
				}
			}
			
			for(c = 1; c le rs_commonTask.recordCount; c++){
				if ( rs_ins['institute_id'][a] eq rs_commonTask['institute_id'][c] ) {
					olap[5] = olap[5] + rs_commonTask['r_count'][c];
				}
			}
			
			for( d = 1; d le rs_taskMark.recordCount; d++){
				
				if ( rs_ins['institute_id'][a] eq rs_taskMark['institute_id'][d] ) {
					
					if ( rs_taskMark['task_prog'][d] eq "3" ) {
						olap[4] = olap[4] + rs_taskMark['r_count'][d];
					}
					else {
						olap[3] = olap[3] + rs_taskMark['r_count'][d];
					}
					
				}
				
			}
			
			arrayAppend( olapArray, olap );
			
		}

		/* 图表数据 */
		/* olapArray [ DepID, DepName, 进行中, 已完成, 未录入 ] */
		
		
		
		/* 读取补考开课学院信息 */
		sql = "	SELECT
					a.institute_id,a.institute_short
				FROM
					t_institute a
				WHERE 
					EXISTS(
						SELECT 1 FROM t_resitplan b INNER JOIN t_course bc ON bc.cid = b.cid
						WHERE
							bc.institute_id = a.institute_id AND b.term_id = :termId 
					)
				ORDER BY
					a.institute_short";
					
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_insRst = queryObj.execute(sql = sql).getResult();

		
		/* 学院补考成绩提交情况 */
		/* olapRstArray [ DepID, DepName, 进行中, 已完成, 未录入 ] */
		
		olapRstArray = [];
		
		/* 补考成绩录入状态 */
		
		sql = "	SELECT
					rpc.institute_id,rp.task_prog,COUNT(*) r_count
				FROM
					t_resitplan rp INNER JOIN t_course rpc ON rpc.cid = rp.cid
				WHERE
					rp.term_id = :termId 
				GROUP BY
					rpc.institute_id,rp.task_prog";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_taskMarkRst = queryObj.execute(sql = sql).getResult();
		
		for( e = 1; e le rs_insRst.recordCount; e++){
			
			/* 重构结果数据 */
			olap = [ rs_insRst['institute_id'][e], rs_insRst['institute_short'][e], 0, 0, 0 ];
			
			for( f = 1; f le rs_taskMarkRst.recordCount; f++ ){
				
				if ( rs_insRst['institute_id'][e] eq rs_taskMarkRst['institute_id'][f] ) {
					
					if ( rs_taskMarkRst['task_prog'][f] eq "3" ) {
						olap[4] = olap[4] + rs_taskMarkRst['r_count'][f];
					}
					else if ( rs_taskMarkRst['task_prog'][f] eq "0" ) {
						olap[5] = olap[5] + rs_taskMarkRst['r_count'][f];
					}
					else {
						olap[3] = olap[3] + rs_taskMarkRst['r_count'][f];
					}
					
				}
				
			}
			
			arrayAppend( olapRstArray, olap );
			
		}
		

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('taskClass')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教学任务</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 setting"></i>成绩提交时间段设置
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="create">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labSetting">class="active"</cfif> id="labSetting" tabTarget="Setting">时间安排</span>
						<span <cfif currentTab eq "labChartFinal">class="active"</cfif> id="labChartFinal" tabTarget="ChartFinal">期末成绩提交进度</span>
						<span <cfif currentTab eq "labChartResit">class="active"</cfif> id="labChartResit" tabTarget="ChartResit">补考成绩提交进度</span>
						<cfif rs_turnEntity.recordCount>
							<span <cfif currentTab eq "labEdit">class="active"</cfif> id="labEdit" tabTarget="Edit">修改<cfoutput>#dictAdvice.getMarkTurnName( rs_turnEntity.mt )#</cfoutput>轮次安排</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<div id="Setting" class="tabContent">
					<div class="noticeBlock">
						<h3>成绩提交时间段</h3>
						<hr/>
					</div>
					
					<table id="turnList" class="UIEditable">
						<thead>
							<tr>
								<td width="80"></td>
								<td width="150">成绩录入日期</td>
								<td width="90">录入时间</td>
								<td width="120">提交时限</td>
								<td>开课学院</td>
								<td width="18"></td>
							</tr>
						</thead>
						<tbody>
                            <cfloop query="rs_turn">
								
								<cfset structInsert(targetArgs, "MT", rs_turn.mt, true) />
								
								<tr class="editRows" rowid="<cfoutput>#rs_turn.mt#</cfoutput>">
									<td><strong><cfoutput>#dictAdvice.getMarkTurnName( rs_turn.mt )#</cfoutput></strong></td>
									<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDateString(rs_turn.date_start, 'YYYY/MM/DD')#</cfoutput> - <cfoutput>#datetimeAdvice.formatDateString(rs_turn.date_end, 'YYYY/MM/DD')#</cfoutput></span></td>
									<td>
										<cfif rs_turn.time_start eq "0001" and rs_turn.time_end eq "2359">
											全天
											<cfelse>
											<span class="numeric"><cfoutput>#datetimeAdvice.formatTimeString(rs_turn.time_start, 'HH:MI')#</cfoutput> ~ <cfoutput>#datetimeAdvice.formatTimeString(rs_turn.time_end, 'HH:MI')#</cfoutput></span>	
										</cfif>
									</td>
									<td>
										<cfif rs_turn.lease_date gt 0>
											考试后 <span class="numeric"><cfoutput>#rs_turn.lease_date#</cfoutput></span> 天
										</cfif>
									</td>
									<td>
										<cfif rs_turn.institute_allowed eq "ALL">全部
											<cfelse>
                                            <cfset sql = "	SELECT
																i.institute_short
															FROM
																t_institute i
															WHERE
																i.institute_id IN (:insIds )" />
                                            
                                            <cfset queryObj = new Query(datasource = application.dnsSlave) />
                                            <cfset queryObj.addParam(name = "insIds", value = rs_turn.institute_allowed, cfsqltype = "cf_sql_varchar", list = true)/>
                                            <cfset rs_insShorts = queryObj.execute(sql = sql).getResult() />
                                            <cfoutput>#valueList(rs_insShorts.institute_short, " | ")#</cfoutput>
										</cfif>
									</td>
									<td><a href="<cfoutput>#buildURL('DEFAULT_EVENT', targetArgs)#</cfoutput>" class="operation edit"></a></td>
								</tr>
								
							</cfloop>
						</tbody>
					</table>
				
				</div>
				
				<div id="ChartFinal" class="tabContent">
					<div class="noticeBlock">
						<h3>成绩提交状态</h3>
						<hr/>
					</div>
					
					<div id="container" style="height:350px; width:740px;"></div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						var chart;
						
						$(document).ready(function() {
							
							chart = new Highcharts.Chart({
								chart: {
									renderTo: 'container', 
									type: 'column'
									},
								title: {
									text: null
									},
								tooltip: {
									borderRadius: 3,
									formatter: function() {
										var s;
										s = '开课部门: ' + this.x  +'<br/>成绩有 ' + this.y + ' 条 ' + this.series.name   + ' 任务';
										return s;
									}
									},
								xAxis: {
									categories: [<cfset i = 0 /><cfloop array="#olapArray#" index="olap"><cfset i++ />'<cfoutput>#olap[2]#</cfoutput>'<cfif i lt arrayLen(olapArray)>,</cfif></cfloop>],
									labels: {
											style: {
												fontSize: '12px'
											}
										}
									},
								yAxis: {
									title: {
										text: null
										}
									},
								credits: {
									enabled: false
									},
								plotOptions: {
									column: {
										stacking: 'percent'
										}
									},
								series: [{
											name: '进行中',
											data: [<cfset i = 0 /><cfloop array="#olapArray#" index="olap"><cfset i++ /><cfoutput>#olap[3]#</cfoutput><cfif i lt arrayLen(olapArray)>,</cfif></cfloop>]
										},
										{
											name: '未录入',
											data: [<cfset i = 0 /><cfloop array="#olapArray#" index="olap"><cfset i++ /><cfoutput>#olap[5]#</cfoutput><cfif i lt arrayLen(olapArray)>,</cfif></cfloop>]
										},
										{
											name: '已完成',
											data: [<cfset i = 0 /><cfloop array="#olapArray#" index="olap"><cfset i++ /><cfoutput>#olap[4]#</cfoutput><cfif i lt arrayLen(olapArray)>,</cfif></cfloop>]
										}]
							});
							
						});
						
						// -->
						//]]>
					</script>
					
				</div>	
				
				<div id="ChartResit" class="tabContent">
					<div class="noticeBlock">
						<h3>补考成绩提交状态</h3>
						<hr/>
					</div>
					
					<div id="containerResit" style="height:350px; width:740px;"></div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						var chartRst;
						
						$(document).ready(function() {
							
							chartRst = new Highcharts.Chart({
								chart: {
									renderTo: 'containerResit', 
									type: 'column'
									},
								title: {
									text: null
									},
								tooltip: {
									borderRadius: 3,
									formatter: function() {
										var s;
										s = '开课部门: ' + this.x  +'<br/>成绩有 ' + this.y + ' 条 ' + this.series.name   + ' 任务';
										return s;
									}
									},
								xAxis: {
									categories: [<cfset i = 0 /><cfloop array="#olapRstArray#" index="olap"><cfset i++ />'<cfoutput>#olap[2]#</cfoutput>'<cfif i lt arrayLen(olapRstArray)>,</cfif></cfloop>],
									labels: {
											style: {
												fontSize: '12px'
											}
										}
									},
								yAxis: {
									title: {
										text: null
										}
									},
								credits: {
									enabled: false
									},
								plotOptions: {
									column: {
										stacking: 'percent'
										}
									},
								series: [{
											name: '进行中',
											data: [<cfset i = 0 /><cfloop array="#olapRstArray#" index="olap"><cfset i++ /><cfoutput>#olap[3]#</cfoutput><cfif i lt arrayLen(olapRstArray)>,</cfif></cfloop>]
										},
										{
											name: '未录入',
											data: [<cfset i = 0 /><cfloop array="#olapRstArray#" index="olap"><cfset i++ /><cfoutput>#olap[5]#</cfoutput><cfif i lt arrayLen(olapRstArray)>,</cfif></cfloop>]
										},
										{
											name: '已完成',
											data: [<cfset i = 0 /><cfloop array="#olapRstArray#" index="olap"><cfset i++ /><cfoutput>#olap[4]#</cfoutput><cfif i lt arrayLen(olapRstArray)>,</cfif></cfloop>]
										}]
							});
							
						});
						
						// -->
						//]]>
					</script>
					
				</div>
				
				<cfif rs_turnEntity.recordCount>
				
					<div id="Edit" class="tabContent">
					
						<div class="noticeBlock">
							<h3><cfoutput>#dictAdvice.getMarkTurnName( rs_turnEntity.mt )#</cfoutput>轮次相关设置</h3>
							<hr/>
						</div>
						
						<form id="formEdit" onSubmit="javascript:return processVerfiyForm('formEdit');" class="formWrapper" method="post" action="<cfoutput>#buildURL('taskMarkTurnUpdateDo')#</cfoutput>">
							
							<input type="hidden" id="MarkTurn" name="MarkTurn" value="<cfoutput>#rs_turnEntity.mt#</cfoutput>" />
							
							<div class="label">
								<span class="req">*</span><b>开始日期</b>
								<input name="DateStart" id="DateStart" type="text" class="typeDate" verification="date" maxlength="10" value="<cfoutput>#datetimeAdvice.formatDateString(rs_turnEntity.date_start)#</cfoutput>" /><span id="startTrigger" class="btnCalendar"></span>
							</div>
							<div class="label">
								<span class="req">*</span><b>结束日期</b>
								<input name="DateEnd" id="DateEnd" type="text" class="typeDate" verification="date" maxlength="10" value="<cfoutput>#datetimeAdvice.formatDateString(rs_turnEntity.date_end)#</cfoutput>" /><span id="endTrigger" class="btnCalendar"></span>
							</div>
							
							<div class="label">
								<span class="req">*</span><b>网上成绩录入开放时间段</b>
								<input name="FullDay" id="FullDay" type="checkbox" class="typeCheckbox" value="1" <cfif rs_turnEntity.time_start eq "0001" and rs_turnEntity.time_end eq "2359">checked="checked"</cfif>/>全天
								<div id="notFullDay" class="<cfif rs_turnEntity.time_start eq "0001" and rs_turnEntity.time_end eq "2359">hidden_elem</cfif>">
									或 指定时间
									<input name="TimeStart" id="TimeStart" type="text" class="typeTime" verification="time" maxlength="5" value="<cfoutput>#datetimeAdvice.formatTimeString(rs_turnEntity.time_start, 'HH:MI')#</cfoutput>" />
									至
									<input name="TimeEnd" id="TimeEnd" type="text" class="typeTime" verification="time" maxlength="5" value="<cfoutput>#datetimeAdvice.formatTimeString(rs_turnEntity.time_end, 'HH:MI')#</cfoutput>" />
								</div>
							</div>
							
							<div class="label">
								<span class="req">*</span><b>提交时限</b>
								<input name="noLeaseDate" id="noLeaseDate" type="checkbox" class="typeCheckbox" value="1" <cfif rs_turnEntity.lease_date eq 0>checked="checked"</cfif>/>规定时间段
								<div id="hasLeaseDate" class="<cfif rs_turnEntity.lease_date eq 0>hidden_elem</cfif>">
									或 指定考试后
									<input name="LeaseDate" id="LeaseDate" type="text" class="typeTinyInt" verification="integer" maxlength="2" value="<cfoutput>#rs_turnEntity.lease_date#</cfoutput>" />
									天内
								</div>
							</div>
							
							<div class="label">
								<b>课程开课学院</b>
								<input name="FullInstitute" id="FullInstitute" type="checkbox" class="typeCheckbox" value="1" <cfif rs_turnEntity.institute_allowed eq "ALL">checked="checked"</cfif>/>所有学院
								<div id="notFullInstitute" class="secondRow <cfif rs_turnEntity.institute_allowed eq "ALL">hidden_elem</cfif>">
									或 <br/> 指定学院
                                    <cfloop query="rs_ins">
										<input name="targetInstitute" type="checkbox" class="typeCheckbox" verification="group" value="<cfoutput>#rs_ins.institute_id#</cfoutput>" <cfif rs_turnEntity.institute_allowed eq "ALL" or listFind(rs_turnEntity.institute_allowed, rs_ins.institute_id, ",")>checked="checked"</cfif> /><cfoutput>#rs_ins.institute_short#</cfoutput>
									</cfloop>
								</div>
							</div>
							
							<div class="lable">
								<input class="button" type="submit" value="更新" />
								<input id="formReset" class="button1" type="reset" value="重设表格" />
							</div>
							
						</form>
						
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							$(document).ready(function() {
								
								$("#DateStart").mask("9999-99-99");
								$("#DateEnd").mask("9999-99-99");
								
								$("#TimeStart").mask("99:99");
								$("#TimeEnd").mask("99:99");
								
								$("#noLeaseDate").change(function(){
									var checked = $(this).prop("checked");
									
									if ( checked ) {
										$("#LeaseDate").val("0");
										$("#hasLeaseDate").addClass("hidden_elem");
									}
									else {
										$("#hasLeaseDate").removeClass("hidden_elem");
									}
									
								});
								
								$("#FullDay").change(function(){
									var checked = $(this).prop("checked");
									
									if ( checked ) {
										$("#TimeStart").val("00:01");
										$("#TimeEnd").val("23:59");
										$("#notFullDay").addClass("hidden_elem");
									}
									else {
										$("#notFullDay").removeClass("hidden_elem");
									}
									
								});
								
								$("#FullInstitute").change(function(){
									var checked = $(this).prop("checked");
									
									if ( checked ) {
										$("#notFullInstitute").addClass("hidden_elem");
									} else {
										$("#notFullInstitute").removeClass("hidden_elem");
									}
								});
								
								
								Calendar.setup({
									trigger    : "startTrigger",
									inputField : "DateStart",
									animation  : false
									});
								
								Calendar.setup({
									trigger    : "endTrigger",
									inputField : "DateEnd",
									animation  : false
									});

							});
							// -->
							//]]>
						</script>
						
					</div>
					
				</cfif>
				
			</div>
		</li>
	</ul>
</div>
					